package _1连接数据库;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo4 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        //2.获取连接
        String url="jdbc:mysql://127.0.0.1/school";
        String username="root";
        String password="root";
        Connection conn =DriverManager.getConnection(url,username,password);

        //3定义SQL语句

        String sql="INSERT INTO stu VALUES(33, '张三')";

        //4.获取执行SQL对象的Statement
        Statement stmt=conn.createStatement();

        //5.执行SQL
        int result=stmt.executeUpdate(sql); //执行完 DML语句，受影响的行数

        //6.处理结果
        System.out.println(result);

        //7.释放资源
        stmt.close();
        conn.close();
    }
}
